<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>用户登录</title>
    <link rel="stylesheet" href="../public/css/login/comment.css" />
  </head>

  <body>
    <div class="bear"></div>

    <div class="mound1"></div>

    <div class="mound2"></div>

    <div class="login-main w">
      <div class="login_title">
        <h2><a href="javascript:;" class="place">Welcome to ZhiLiao</a></h2>
      </div>
      <form action="/login" id="login_form" method="post">
        <div class="username">
          <input
            type="text"
            name="nickname"
            id="nickname"
            placeholder="请输入用户名"
            autocomplete="off"
            required
            value=""
          />
        </div>
        <div class="email">
          <input
            type="text"
            name="email"
            id="email"
            placeholder="请输入邮箱"
            autocomplete="off"
            required
            value=""
          />
        </div>
        <div class="password">
          <input
            type="password"
            name="password"
            id="password"
            placeholder="请输入密码"
            autocomplete="off"
            required
            value=""
          />
        </div>
        <div class="next_login"><input type="checkbox" /> 下次自动登录</div>
        <div class="button">
          <input type="submit" id="login" value="登录" />
        </div>

        <div class="login_footer">
          <a href="/404" class="forget">忘记密码？</a>
          <a href="/register" class="to_register">注册新用户</a>
        </div>
      </form>
    </div>
  </body>
  <script src="../public/js/src/jQuery.js"></script>
  <script>
    $("#login_form").on("submit", function (e) {
      e.preventDefault();
      var formData = $(this).serialize();
      // console.log(formData);
      $.ajax({
        url: "/login",
        type: "POST",
        data: formData,
        dataType: "json",
        success: function (data) {
          var err_code = data.err_code;
          if (err_code === 1) {
            window.alert("登录成功！");
            window.location.href = "/app";
          } else if (err_code === 0) {
            window.alert("该不用户存在，请重新登录！");
          } else if (err_code === 500) {
            window.alert("服务器忙，请稍后重试！");
          }
        },
      });
    });
  </script>

  <script>
    const place = document.querySelector(".place");
    place.addEventListener("click", () => {
      alert("请知了登录用户!");
    });
  </script>
</html>
